import java.util.Arrays;
import java.util.Scanner;

public class Class2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i=0;i<t;i++){
            long[] a = new long[5];
            for (int j=0;j<5;j++){
                a[j] = scanner.nextInt();
            }
            Arrays.sort(a);
            long ans = a[1];
            for (int j=1;j<5;j++){
                a[j] = a[j] -ans;
            }
            Arrays.sort(a);
            int flag =0;
            for (int j=2;j<5;j++){
                if (a[j]<=0)
                    flag=1;
            }
            if (flag==0){
                System.out.println(ans+a[1]);
            }else {
                System.out.println(ans);
            }

        }
    }
}
